Crate tower_cookies[][src]

Expand description

A cookie manager middleware built on top of tower.

Example

With axum:

use axum::{routing::get, Router};
use std::net::SocketAddr;
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(handler))
        .layer(CookieManagerLayer::new());

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

async fn handler(cookies: Cookies) -> &'static str {
    cookies.add(Cookie::new("hello_world", "hello_world"));

    "Check your cookies."
}

A complete CRUD cookie example in examples/counter.rs

Modules

Middleware to use Cookies.

Structs

Representation of an HTTP cookie.

Middleware to use Cookies.

Layer to apply CookieManager middleware.

A parsed on-demand cookie jar.